<template>
    <div>
        <div class="historyBody">
            <!-- 弹出框 -->
            <div class="alertbodyBox" :class="{noalert:show}">
                <div class="alertbox">
                    <div class="alertTop">
                        弹框提示
                        <img src="../../assets/img/plan/images/close_03.png" alt="" @click="close">
                    </div>
                    <span>
                        开奖期数超过1000期，请重新导入
                    </span>
                </div>
            </div>
            <!-- 顶部栏 -->
            <div class="historyTop">
                <span>选择玩法:</span>
                <div class="historyRadio">
                    <el-checkbox-group v-model="checkList" >
                        <el-checkbox v-for="(item, index) in wanfaarr" :label="index" :key="index">{{item.title}}</el-checkbox>
                    </el-checkbox-group>
                    
                </div>
                <span class="titleTwo">选择期数：</span>
                <div class="select">
                    <input type="text" id="input" v-model="writedata" @change="changeWritedata">
                    <select id="engine2" v-model="writedata">
                        <option value="100">100</option>
                        <option value="300">300</option>
                        <option value="500">500</option>
                        <option value="700">700</option>
                        <option value="900">900</option>
                        <option value="1000">1000</option>
                    </select>
                </div>
                <div class="updatedata toData">
                    <input  name="file" type="file" accept="txt" class="file" @change="update"/>
                    <span>导入数据</span>
                </div>
                <div class="updatedata" @click="updateData">
                    更新数据
                </div>
                
            </div>
            <!-- 开奖数据 -->
            <div class="showData">
                <Table :tabletitleData="headdata"  :tableData="resultdata"></Table>                
            </div>
            <!-- 右侧数据 -->
            <div class="dataRight">
                <!-- 进度条 -->
                <div class="updateIng">
                    <!-- 正在更新 -->
                    <Progress ref="startprogress" :timego="timestartgo" :timeend="endtime"></Progress>
                </div>
                <!-- 结果 -->
                <div class="updateResult">
                    <span class="result">结果：验证<i>{{this.writedata}}</i>期</span>
                    <span class="correctRate">准确率：<i>{{this.truerate}}</i></span>
                </div>
                <!-- 验证期数 -->
                <div class="dateNum">
                    <div class="datenumBox">
                        <div>
                            <div class="numWord">正确期数</div>
                            <div class="dateNumber">
                                {{rightdata.right_expect_num}}
                            </div>
                            期
                        </div>
                    </div>
                    <div class="datenumBox">
                        <div>
                            <div class="numWord">错误期数</div>
                            <div class="dateNumber">
                                {{rightdata.false_expect_num}}
                            </div>
                            期
                        </div>
                    </div>
                    <div class="datenumBox">
                        <div>
                            <div class="numWord">连中期数</div>
                            <div class="dateNumber">
                                {{rightdata.con_right_expect_num}}
                            </div>
                            期
                        </div>
                    </div>
                    <div class="datenumBox">
                        <div>
                            <div class="numWord">连错期数</div>
                            <div class="dateNumber">
                                {{rightdata.con_false_expect_num}}
                            </div>
                            期
                        </div>
                    </div>
                    <div class="datenumBox">
                        <div>
                            <div class="numWord">当前遗漏</div>
                            <div class="dateNumber">
                                {{rightdata.omission_num}}
                            </div>
                            期
                        </div>
                    </div>
                </div>
                <!-- 我的号码 -->
                <div class="myNum">
                    <div class="mynumTitle">
                        <div class="myNumber">我的号码：共<i>{{this.dataNum}}</i>注</div> 
                        <!-- <div class="error" :class="{errornone:shownone == 0}">号码输入错误！</div> -->
                        <div v-if="errorshow" class="error" >{{errormsg}}</div>
                    </div>
                    <div class="writeNum">
                        <textarea v-model="stringData" :maxlength="datalength" id="text" type="number"  @keyup="changenumFn">
                            
                        </textarea>
                    </div>
                    <div class="startYz" @click="startYz">
                        开始验证
                    </div>
                    <div class="startYz copyYz" @click="copytext">
                        复制号码
                    </div>
                    <div class="startYz copyYz" @click="cleartext">
                        清空号码
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
import Table from '../Table'
import Progress from '../plan/progress'
export default {
    components: {
        Table,
        Progress
    },
     data () {
      return {
        show:true,
        endtime:500,
        timestartgo:0,
        fileList:[],
        token:{
            accessToken:''
        },
        writedata:30,  //选择期数值
        checkList: [],   //玩法
        dataNum:0,   //号码注数
        stringData:"",  //输入号码
        errorshow: false,
        errormsg: '',
        datalength: '',  //最大长度
        headdata:[
            {
                title:"periods",
                name:"开奖期数"
            },
            {
                title:"open_code",
                name:"开奖号码"
            },
            {
                title:"is_right",
                name:"结果"
            }
        ], //表头
        resultdata:[], //表格数据
        shownone:0,  //号码输入错误提示是否显示
        rightdata:{},
        truerate:'0.00%',
        wanfaarr: [],
        sscarr: [
            {title: '万'},
            {title: '千'},
            {title: '百'},
            {title: '十'},
            {title: '个'},
        ],
        jndarr: [
            {title: '百'},
            {title: '十'},
            {title: '个'},
        ],
        beijingarr: [
            {title: '冠军'},
            {title: '亚军'},
            {title: '季军'},
            {title: '第四名'},
            {title: '第五名'},
        ],
        jsuarr: [
            {title: '第一位'},
            {title: '第二位'},
            {title: '第三位'},
        ]
      }
    },
    computed: {
        lotteryid(){
            return this.$store.state.lottery_id
        }
    },
    watch:{
        lotteryid(){
            var self = this

            self.errorshow = false   
            self.checkList = []
            self.rightdata = {}

            this.planFn()

            
            this.resultdata = []
            this.dataNum = 0
            this.stringData = []
            this.writedata = 30
            this.truerate = '0.00%'
           
        },
        stringData:function(){
            if(this.stringData.length>0){
                let arrData=this.stringData.split(" ");
                for(var i=0,len=arrData.length;i<len;i++){
                    if(!arrData[i]|| arrData[i]==''){
                        arrData.splice(i,1);
                        len--;
                    }
                }
                this.dataNum=arrData.length;
                this.shownone=0;
            }
            
        }
    },
    created(){
        this.planFn()
    },
    methods:{    
        planFn(){
            var self = this
            if(self.$store.state.CaiPiaoType == 'ssc' || self.$store.state.CaiPiaoType == 'l11x5'){
                self.wanfaarr = self.sscarr
            }
            if(self.$store.state.CaiPiaoType == 'pk10'){
                self.wanfaarr = self.beijingarr
            }
            if(self.$store.state.CaiPiaoType == 'l28' || self.$store.state.CaiPiaoType == 'l3d'){
                self.wanfaarr = self.jndarr
            }
            if(self.$store.state.CaiPiaoType == 'k3'){
                self.wanfaarr = self.jsuarr
            }
        },
        changenumFn(){             
            if(this.stringData.length>1){
                this.stringData=this.stringData.replace(/[^0-9\u0020]/g,'')

                if(this.checkList.length == 1){
                    if(this.dataNum>=10){                        
                        this.errorshow = true
                        this.errormsg = '定位胆最多输入10注'
                        this.datalength = this.stringData.length
                    } else {
                        this.errorshow = false
                        this.errormsg = ''
                        this.datalength = ''
                    }
                    return
                }

                if(this.checkList.length == 2){
                    if(this.dataNum>100){                        
                        this.errorshow = true
                        this.errormsg = '二星直选最多输入100注'
                     this.datalength = this.stringData.length
                    } else {
                        this.errorshow = false
                        this.errormsg = ''
                        this.datalength = ''
                    }
                    return
                }

                if(this.checkList.length == 3){
                    if(this.dataNum>1000){                        
                        this.errorshow = true
                        this.errormsg = '三星直选最多输入1000注'
                    this.datalength = this.stringData.length
                    } else {
                        this.errorshow = false
                        this.errormsg = ''
                        this.datalength = ''
                    }
                    return
                }

                if(this.checkList.length == 4){
                    if(this.dataNum>1000){                        
                        this.errorshow = true
                        this.errormsg = '四星直选最多输入10000注'
                     this.datalength = this.stringData.length
                    } else {
                        this.errorshow = false
                        this.errormsg = ''
                        this.datalength = ''
                    }
                    return
                }

                if(this.checkList.length == 5){
                    if(this.dataNum>1000){                        
                        this.errorshow = true
                        this.errormsg = '三星直选最多输入100000注'
                    } else {
                        this.errorshow = false
                        this.errormsg = ''
                        this.datalength = ''
                    }
                    return
                }
            
            }
            
            

        },
        changeWritedata(){
            if(this.writedata>1000){
                this.writedata=1000;
            }else if(this.writedata<=0){
                this.writedata=1;
            }
        },
        // 更新数据
        updateData(){
            this.$refs.startprogress.start();
            if(!this.writedata){
                this.$toast({
                    message: '请选择期数'
                })
                return
            }

            setTimeout(()=>{
                this.https("Analyse/getClientHistoryLotteryRecordLimit",{lottery_id:this.$store.state.lottery_id,limit:this.writedata}).then(data=>{
                        // this.resultdata=data;
                        if(this.lotteryid == 10){
                            data.forEach(element => {
                                element.open_code = element.open_code.substring(0,14) + ' \n ' + element.open_code.substring(15,29)
                            });
                            this.resultdata=data
                        }else{
                            this.resultdata=data
                        }
                })
            },5500)
            
        },
        // 开始验证
        startYz(){
            
            if(!this.stringData){
               this.$toast({
                    message: '请输入号码'
                })
                return
            }

            if(this.checkList.length<1){
               this.$toast({
                    message: '请选择玩法'
                })
                return
            }


            let arrData=this.stringData.split(" ");

            var condition1, condition2, condition3, condition4, condition5, condition6, condition7, condition8, condition9, condition10
            arrData.forEach(aditem => {
                condition1 = (this.checkList.length == 1 && aditem.length !=1)
                condition2 = (this.checkList.length == 2 && aditem.length !=2)
                condition3 = ( this.checkList.length == 3 && aditem.length !=3)
                condition4 = (this.checkList.length == 4 && aditem.length !=4)
                condition5 = (this.checkList.length == 5 && aditem.length !=5)

                condition6 = (this.checkList.length == 1 && (aditem.length !=2))
                condition7 = (this.checkList.length == 2 && (aditem.length !=4))
                condition8 = (this.checkList.length == 3 && (aditem.length !=6))
                condition9 = (this.checkList.length == 4 && (aditem.length !=8))
                condition10 = (this.checkList.length == 5 && (aditem.length !=10))
            })


            if(this.$store.state.CaiPiaoType == 'pk10' || this.$store.state.CaiPiaoType == 'l11x5'){

                    if(condition6 || condition7 || condition8 || condition9 || condition10){
                        this.errorshow = true
                        this.errormsg = '号码验证中存在不符合位数的号码，请重新输入'
                            return
                    } 

                    var indexone, indextwo, indexthree, indexfore, indexfive
                    
                    for(var i=0; i<arrData.length; i++) {

                        if(arrData[i].length==2 && ((this.$store.state.CaiPiaoType == 'pk10' && arrData[i]>10) || (this.$store.state.CaiPiaoType == 'l11x5' && arrData[i]>11))){
                            this.errorshow = true
                            this.errormsg = '号码验证中存在不符合位数的号码，请重新输入'
                            return
                            
                        }

                        if(arrData[i].length==4){
                            indexone = arrData[i].substring(0,2)
                            indextwo = arrData[i].substr(2,2)
                            
                            if(this.$store.state.CaiPiaoType == 'l11x5' && (indexone > 11 || indextwo > 11) ){
                                this.errorshow = true
                                this.errormsg = '号码验证中存在不符合位数的号码，请重新输入';
                                return
                                
                            }

                            if(this.$store.state.CaiPiaoType == 'pk10' && (indexone > 10 || indextwo > 10) ){
                                this.errorshow = true
                                this.errormsg = '号码验证中存在不符合位数的号码，请重新输入'
                                return
                            }
                            
                            
                        }

                        if(arrData[i].length==6){
                            indexone = arrData[i].substring(0,2)
                            indextwo = arrData[i].substr(2,2)
                            indexthree = arrData[i].substr(4,2)

                            if(this.$store.state.CaiPiaoType == 'l11x5' && (indexone > 11 || indextwo > 11 || indexthree > 11) ){
                                this.errorshow = true
                                this.errormsg = '号码验证中存在不符合位数的号码，请重新输入'
                                return false
                            }

                            if(this.$store.state.CaiPiaoType == 'pk10' && (indexone > 10 || indextwo > 10  || indexthree > 10) ){
                                this.errorshow = true
                                this.errormsg = '号码验证中存在不符合位数的号码，请重新输入'
                                return false
                            }
                            
                        }

                        if(arrData[i].length==8){
                            indexone = arrData[i].substring(0,2)
                            indextwo = arrData[i].substr(2,2)
                            indexthree = arrData[i].substr(4,2)
                            indexfore = arrData[i].substr(6,2)
                            
                            if(this.$store.state.CaiPiaoType == 'l11x5' && (indexone > 11 || indextwo > 11 || indexthree > 11 || indexfore > 11) ){
                                this.errorshow = true
                                this.errormsg = '号码验证中存在不符合位数的号码，请重新输入'
                                return false
                            }

                            if(this.$store.state.CaiPiaoType == 'pk10' && (indexone > 10 || indextwo > 10  || indexthree > 10  || indexfore > 10) ){
                                this.errorshow = true
                                this.errormsg = '号码验证中存在不符合位数的号码，请重新输入'
                                return false
                            }
                        }

                        if(arrData[i].length==10){
                            indexone = arrData[i].substring(0,2)
                            indextwo = arrData[i].substr(2,2)
                            indexthree = arrData[i].substr(4,2)
                            indexfore = arrData[i].substr(6,2)
                            indexfive = arrData[i].substr(8,2)
                            if(this.$store.state.CaiPiaoType == 'l11x5' && (indexone > 11 || indextwo > 11 || indexthree > 11 || indexfore > 11 || indexfive > 11) ){
                                this.errorshow = true
                                this.errormsg = '号码验证中存在不符合位数的号码，请重新输入'
                                return
                            }

                            if(this.$store.state.CaiPiaoType == 'pk10' && (indexone > 10 || indextwo > 10  || indexthree > 10  || indexfore > 10 || indexfive > 10) ){
                                this.errorshow = true
                                this.errormsg = '号码验证中存在不符合位数的号码，请重新输入'
                                return
                            }
                        }

                    }              
                } else{
                    if(condition1 || condition2 || condition3 || condition4 || condition5){
                        this.errorshow = true
                        this.errormsg = '号码验证中存在不符合位数的号码，请重新输入'
                        return
                    }   
                }

            this.$refs.startprogress.start();

            setTimeout(()=>{
                let arr=this.checkList;
                var str = "";
                for (var i =0;i<arr.length;i++) {
                    str += arr[i]+",";
                }
                str=str.substr(0,str.length-1);
                var params = {
                    lottery_id:this.$store.state.lottery_id,
                    limit:this.writedata,
                    play_bit:str,
                    validate_data:this.stringData,
                    list:this.resultdata
                }
                this.https("Analyse/postStartValidationLotteryRecordLimit",params,'post').then(data=>{
                    this.rightdata=data;
                    this.truerate = data.percentage;
                    let arr = data.data;
                    arr.forEach(item=>{
                        if(item.is_right==0){
                            item.is_right="×"
                        }else if(item.is_right==1){
                            item.is_right="√"
                        }
                    })
                    this.resultdata=arr;
                })
            },5500)               
        },
        
        // 复制号码
        copytext(){
                let ele = document.getElementById("text");
                ele.select();
                document.execCommand("Copy");
        },
        // 清空号码
        cleartext(){
            this.stringData = ''
                // document.getElementById('text').value='';
        },
        // 点击上传
        update(e){
            let file = e.target.files[0];
            let param = new FormData(); 
            param.append('record_file', file, file.name); 
            param.append('chunk', '0'); 
            this.https('Analyse/postImportTxtData',param,'formData')
            .then(data=>{
                this.writedata = data.total_num
                if(data.total_num>1000){
                    this.show=false;
                }else{
                    this.resultdata=data.data;
                }
            })
        },
        close(){
            this.show=true;
        }
    }
}
</script>

<style lang='less' scoped>
    @import url(../../assets/css/index/indexhistory.less);
</style>
<style>
.historyBody .el-progress__text i{
    opacity: 0;
}
.historyBody .el-button--mini, .el-button--small{
    font-size:0.12rem;
}
.historyBody .el-button--primary.is-active, .el-button--primary:active{
    background: #e52a20;
    border-color: #e52a20;
}
.historyBody .el-button--primary:focus, .el-button--primary:hover{
    background: #e52a20;
    border-color: #e52a20;
}
.historyBody .el-checkbox__input.is-checked+.el-checkbox__label{
    color:#333333;
}
.historyBody .el-checkbox__label{
    padding-left:0.03rem;
    font-size: 0.11rem;
    font-weight: bold;
}
.historyBody .el-checkbox__input.is-checked .el-checkbox__inner, .el-checkbox__input.is-indeterminate .el-checkbox__inner{
    background-color: #E52A20 !important;
    border-color:#dcdfe6 !important;
}
.historyBody .el-checkbox{
    height: 100%;
    float: left;
}
.historyBody .el-checkbox__input{
    font-size:0.13rem;
    color:#999999;
    line-height:0.13rem;
}
.historyBody .el-checkbox+.el-checkbox{
    margin-left:0.1rem;
}
.historyBody .upload-demo,.el-upload,.el-button--primary{
    width: 0.67rem;
    height: 0.25rem;
    border-radius: 0.02rem;
    text-align:center !important;
    background-color:#fff;
    color:#333333;
}
.historyBody .el-button{
    padding:0;
}
.historyBody .el-upload-list{
    display:none;
}
</style>




